package com.hhc.template;

/**
 * 示例中，CookingTemplate 是抽象模板类，它定义了炒菜的算法骨架，包括选材、切菜、炒菜、放调料等步骤。
 * 具体子类 StirFry 继承自抽象模板类，并提供了选材、切菜、炒菜等具体实现。addSeasonings 方法是一个钩子方法，可以在子类中选择性地重写。
 */

// 抽象模板类
abstract class CookingTemplate {
    public void cook() {
        selectIngredients();
        cutIngredients();
        cookDish();
        addSeasonings();
    }

    protected abstract void selectIngredients();

    protected abstract void cutIngredients();

    protected abstract void cookDish();

    protected void addSeasonings() {
        System.out.println("Add seasonings: salt, pepper, soy sauce, etc.");
    }
}

// 具体子类
class StirFry extends CookingTemplate {
    @Override
    protected void selectIngredients() {
        System.out.println("Select fresh vegetables and protein.");
    }

    @Override
    protected void cutIngredients() {
        System.out.println("Cut the vegetables and protein into small pieces.");
    }

    @Override
    protected void cookDish() {
        System.out.println("Stir-fry the ingredients in a hot wok.");
    }
}

public class CookingDemo {
    public static void main(String[] args) {
        CookingTemplate stirFry = new StirFry();
        stirFry.cook();
    }
}
